'''
Experiment Use Case Tests

1) Make an Experiment (check values)
2) Edit experiment (check values)
3) Delete experiment
'''

from interactive import *

#1)
css("#ColonyView")
linkpart("EPO").click()
twait()

css("#ColonyMenu")
linkpart("Experiments").click()
twait()

New()
twait()

css("#ExperimentDetail")
css("#ExperimentDetail #Name").send_keys("Test Experiment")
css("#ExperimentDetail #Priority").send_keys("4")
css("#ExperimentDetail #Comment").send_keys("This is an experiment test")
Done()
twait()

#css("#ColonyMenu")
#linkpart("Experiments").click()
#twait()

css("#ExperimentView")
Edit()
linkpart("Test Experiment").click()
twait()

assert(css("#ExperimentDetail #Name").get_attribute("value") == "Test Experiment")
assert(css("#ExperimentDetail #Priority").get_attribute("value") == "4")
assert(css("#ExperimentDetail #Comment").get_attribute("value") == "This is an experiment test")

#2) 

Edit()
css("#ExperimentDetail #Name").clear()
css("#ExperimentDetail #Name").send_keys("Altered Test Experiment")
css("#ExperimentDetail #Priority").clear()
css("#ExperimentDetail #Priority").send_keys("2")
css("#ExperimentDetail #Comment").clear()
css("#ExperimentDetail #Comment").send_keys("This is a changed experiment test")
Done()
twait()
twait() 

#css("#ColonyMenu")
#linkpart("Experiments").click()
#twait()

css("#ExperimentView")
Edit()
linkpart("Altered Test Experiment").click()
twait()

css("#ExperimentDetail")
assert(css("#ExperimentDetail #Name").get_attribute("value") == "Altered Test Experiment")
assert(css("#ExperimentDetail #Priority").get_attribute("value") == "2")
assert(css("#ExperimentDetail #Comment").get_attribute("value") == "This is a changed experiment test")

Back()
twait()

#3)


css("#ExperimentView")
Edit()
driver.execute_script("return $('#ExperimentView li').has (':contains(\"Altered Test Experiment\")').find('a').has('.ui-icon-delete')[0]").click()
alert = driver.switch_to_alert()
assert(alert.text == "Are you sure you wish to delete Altered Test Experiment?")
alert.accept()

driver.quit()
